/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.classdiagram.editpart;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.XYLayout;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.eclipse.gef.requests.CreateRequest;

import com.cea.papyrus.core.editpart.LayoutEditPolicy;
import com.cea.papyrus.core.utils.Debug;

/**
 * LayoutEditPolicy for the Class Diagram.
 */
public class ClassElementLayoutEditPolicy extends LayoutEditPolicy {

	/**
	 * Creates a new {@link ClassElementLayoutEditPolicy} with the given layout.
	 * 
	 * @param layout the layout of the diagram
	 */
	public ClassElementLayoutEditPolicy(XYLayout layout) {
		super(layout);
	}

	protected Command getAddCommand(Request generic) {
		ChangeBoundsRequest request = (ChangeBoundsRequest)generic;
		List editParts = request.getEditParts();
		List newList = new ArrayList() ;
		for (int i = 0; i < editParts.size(); i++) {
			if (!(editParts.get(i) instanceof TemplateSignatureEditPart)) {
				newList.add(editParts.get(i)) ;
			}
		}
		((ChangeBoundsRequest)generic).setEditParts(newList) ;
		return super.getAddCommand(generic) ;
	}
	
	protected Command createChangeConstraintCommand(ChangeBoundsRequest request, 
			EditPart child, Object constraint) {
		if (child instanceof TemplateSignatureEditPart) {
			return null ;
		}
		return super.createChangeConstraintCommand(request, child, constraint);
	}
	protected Command getCreateCommand(CreateRequest request) {
		Debug.debug(this, "createElement in class Element", channel);
		return super.getCreateCommand(request);
	}
}
